package cool.webstudy.admin.constant.enums.rescode;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author think
 * @date 2024/7/15 23:13
 * @description: 通用响应码枚举
 */
@Slf4j
public enum CommonResCodeEnum implements BaseResCodeEnum {
    RC_FAILURE("-1","请求失败！"),
    RC_SUCCESS("200","请求成功！"),
    RC_PARAM_NOTNULL("400","请求参数：{0}不能为空"),
    RC_PARAM_MISS("400","请求参数：{0}缺失！"),
    RC_UNKNOWN_ERROR("500","未知异常！")
    ;
    private String code;
    private String msg;
    CommonResCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    @Override
    public String code() {
        return code;
    }

    @Override
    public String msg() {
        return msg;
    }
    /**
     * 根据code获取msg静态方法，每个响应状态码枚举类都应有这个方法
     */
    public static CommonResCodeEnum getMsgByCode(String code) {
        for (CommonResCodeEnum commonResCodeEnum : CommonResCodeEnum.values()) {
            if (commonResCodeEnum.code().equals(code)) {
                return commonResCodeEnum;
            }
        }
        log.error("getMsgByCode error:无法获取枚举值");
        return CommonResCodeEnum.RC_UNKNOWN_ERROR;
    }
}
